package com.persia.controller;

import com.persia.domain.TechBook;
import com.persia.service.BookService;
import com.persia.tool.StringTool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author caibosi
 * @created 2014-02-07
 */
@Controller
public class IndexController {

    private static final Logger logger = LoggerFactory.getLogger(IndexController.class);

    @Resource
    private BookService bookService;

    @RequestMapping("/")
    @ResponseBody
    public String index(){
        return "this is index";
    }

    @RequestMapping("/book/list")
    @ResponseBody
    public String testBook(){
        TechBook book = new TechBook();
        book.setTitle("hello1");
        book.setCreateAt(new Date());
        bookService.insert(book);

        List<TechBook> books = bookService.getAll();
        String content = StringTool.toFriendlyString(books,",");
        logger.info(content);
        return content;
    }
}
